﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Controls
{
    public partial class PsFile : UserControl
    {
        #region 与其他控件相同的属性
        private string _editMode;

        public virtual string EditMode
        {
            get { return _editMode; }
            set { _editMode = value; }
        }

        private bool _isRequie = false;

        public virtual bool IsRequie
        {
            get { return _isRequie; }
            set { _isRequie = value; }
        }

        private string _lable;

        public virtual string Lable
        {
            get { return _lable; }
            set { _lable = value; }
        }

        private bool _sysReadOnly = false;
        public string DisplayMode;

        public virtual bool SysReadOnly
        {
            get { return _sysReadOnly; }
            set { _sysReadOnly = value; }
        }
        #endregion

        public PsFile()
        {
            InitializeComponent();
        }

        private void btnLook_Click(object sender, EventArgs e)
        {
            OpenFileSelectDilag(); //打开文件选择框
        }

        /// <summary>
        /// 打开文件选择对话框
        /// </summary>
        void OpenFileSelectDilag()
        {
            if (ofdMain.ShowDialog() == DialogResult.OK)
            {
                this.txtFileInput.Text = ofdMain.FileName;
            }
        }

        private void txtFileInput_ValueChanged(object sender, EventArgs e)
        {
            string filePath = this.txtFileInput.Text; //当前文件名
            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            //如果用户手工输入的路径不存在，那么提醒用户
            if (!System.IO.File.Exists(filePath))
            {
                MessageBox.Show(string.Format("文件{0}不存在！", filePath), "提示");
                this.txtFileInput.Clear();
            }
        }

        private void txtFileInput_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            OpenFileSelectDilag(); //在路径输入框上面双击，也可打开文件选择框
        }

        /// <summary>
        /// 获得或设置当前文件选择框的位置
        /// </summary>
        public string FilePath
        {
            get
            {
                return txtFileInput.Text;
            }
            set
            {
                this.txtFileInput.Text = value;
            }
        }

        
    }
}
